/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.shooter;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.shooter.level.ScoreManager;

/**
 *
 * @author Unni vemanchery Mana
 * 
 * This class is used to throw bomb to player ship.
 * Bomber  will  move to player position and fire the bomb
 * Once the player is hit, it's life will reduce and device will
 * register a vibration
 * 
 */
public final class Bomber {
    private Sprite bombSprite ;
    private final String bombTexture = "enemy-bullet.png";
    private Texture texture;
    private float x;
    private float y;
    private Bomb [] bombs = new Bomb[3];
    private int counter   = 0;
    private Bomb b ;
    private boolean isCollided    = false;
    private Player player;
    private ScoreManager scoreManager;
    private SpriteExplode se;
    
    private boolean loadBomb;
    private Rectangle bombbounds = new Rectangle();
    public Bomber(Player player){
     this.player = player;   
     initializeBomber();
     scoreManager = new ScoreManager();
    }
    private void initializeBomber(){
      for(int i = 0; i<1; i++){
          Bomb  bb = new Bomb();
          bb.x     = 0;
          bb.y     = 0;
          bombs[i] = bb;
      }
      Texture.setEnforcePotImages(false);  
      texture    = new Texture(Gdx.files.internal(bombTexture));
      bombSprite = new Sprite(texture);
      bombbounds = bombSprite.getBoundingRectangle();
    }
    
    public void drawBomber(SpriteBatch batch){
      if(!loadBomb) return;
      isCollided = CollisionManager.checkSimpleCollison(bombbounds, player.getBounds());
      Explosion explosion = player.getExplosion();
      
      if(isCollided){
        //  player.getExplosion().explode(batch, (int)player.getPosition().x, (int)player.getPosition().y, player);
            explosion.showExplosion = true;
     } 
      explosion.explode(batch, (int)player.getPosition().x, (int)player.getPosition().y, player);
      bombSprite.setPosition(b.x, b.y);
      bombSprite.draw(batch);
      b.y = b.y - b.speed;
      bombbounds.y = b.y;
      bombbounds.x = b.x;
    }
    
    public void loadBomber(int x, int y){
        b      = bombs[counter]; 
        b.x    = x;
        b.y    = 320;
        this.x = x;
        this.y = y;
        loadBomb = true;
    } 
    private class Bomb {
        private float x;
        private float y;
        private int speed = 7;
    }
}
